<template>
	<view class="">
		<u-action-sheet :actions="recordsList" round="24" :description="description" :closeOnClickAction="true" @select="selectClick" @close="close" :show="showAction" cancelText="取消" :safeAreaInsetBottom="true" ></u-action-sheet>
		
	</view>
</template>

<script>
	import { getCurrentUserDeparts, selectDepart } from '@/api/index.js'
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				description:'选择部门',
				recordsList: [],
				showAction: false,
			};
		},
		onLoad() {},
		watch: {
			show: {
				handler (val) {
					if (val) {
						this.getRecords()
					} else {
						this.showAction = val
					}
				},
				immediate: true
			}
		},
		methods: {
			// 获取数据
			getRecords () {
				getCurrentUserDeparts().then(res => {
					if (res.success) {
						if (res.result.list && res.result.list.length) {
							res.result.list.map(value => {
								value.name = value.departName
								if (res.result.orgCode == value.orgCode) {
									value.color = '#1E6FFF'
								}
								return value
							})
							if (res.result.list.length>1) {
								this.showAction = true
							} else {
								this.showAction = false
								this.$emit('choice', true)
							}
						} else {
							this.showAction = false
							this.$emit('choice', true)
						}
					}
					this.recordsList = res.result.list
				}).catch(res => {
					
				})
			},
			
			selectClick(item){
				var params = {
					orgCode: item.orgCode
				}
				selectDepart(params).then(res => {
					if (res.success) {
						this.$emit('click', res.result.userInfo)
					}
				}).catch(res => {
					
				})
			},
			
			close() {
				this.$emit('close')
			}
		}
	};
</script>

<style>
</style>